@extends('admin.common.main')
@section('css')
<style>
</style>
@endsection
@section('cnt')
<div class="x-body page-container">
    @include('admin.common.validate')
    @include('admin.common.msg')
    <form  @submit.prevent="dopost" method="post" action="{{ route('admin.node.store') }}">
		<div class="layui-form-item">
				  <label for="username" class="layui-form-label">
					  <span class="x-red">*</span>是否顶级
				  </label> 
				  <div class="layui-input-inline" >
					  <select name="pid" id="pid" @change="changePid">
						<option value="0">==顶级==</option>
						@foreach($data as $item)
							<option value="{{ $item->id }}">{{ $item->name }}</option>
						@endforeach
					  </select>
				  </div>
			  </div>
          
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>节点名称
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="name" name="name" required=""
                  autocomplete="off" class="layui-input" v-model="info.name"  >
              </div>
          </div>
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>路由别名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="route_name" name="route_name" 
                  autocomplete="off" class="layui-input" v-model="info.route_name">
              </div>
          </div>
         
           <div class="layui-form-item">
              <label class="layui-form-label"><span class="x-red">*</span>是否菜单</label>
              <div class="layui-input-block">
                否<input type="radio" name="is_menu" lay-skin="primary" title="否" value="0" v-model="info.is_menu">
                是<input type="radio" name="is_menu" lay-skin="primary" title="是" value="1" v-model="info.is_menu">
              </div>
          </div>
         
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" type="submit">
                  添加节点
              </button>
          </div>
      </form>
</div>
@endsection
@section('js')
<script src="/js/vue.js"></script>
<script>

    new Vue({
		el : '.page-container',
		data:{
			info:{
				_token:"{{ csrf_token() }}",
				pid:0,
				name:'',
				route_name:'',
				is_menu:0
			}
		},
		methods:{
			/*dopost(evt){
				//console.log(evt.target.getAttribute('action'))
				let url = evt.target.action;
				$.post(url,this.info).then(ret => {
					console.log(ret)
				});
			}*/
			
			
			
			//异步变同步 es7 async await
			async dopost(evt){
				let url = evt.target.action;
				let {status,msg} = await $.post(url,this.info);
				//console.log(status)
				if(status == 0){
                    layer.msg(msg,{icon:1,time:1000},function(){
                        var index=parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        window.parent.location.reload();
                    })
                }else{
                    layer.msg(msg);
                }
			},
			//下拉
			changePid(evt){
				//下拉的值   ect.target.select 的dom对象
				this.info.pid = evt.target.value || 0;
			}
			
		}
	})


</script>
@endsection